#include "musicplayer.h"

MusicPlayer::MusicPlayer(QWidget *parent)
{
    player = new Phonon::VideoPlayer(Phonon::VideoCategory, parent);
    mediaSource = NULL;
    index = -1;
    connect(player, SIGNAL(finished()), this, SLOT(play()));
}

MusicPlayer::~MusicPlayer()
{
    player->stop();
}

void MusicPlayer::setMusic(QList<QString>* musicPath)
{
    this->musicPath = *musicPath;
    play();
}

void MusicPlayer::play()
{
    delete mediaSource;
    mediaSource = new Phonon::MediaSource(musicPath.at(index));
    index = (index + 1) % musicPath.size();
    player->load(*mediaSource);
    player->play();
}
